<?php
ob_start();
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database"); 

// find user ID from name
$query="select ID from Account where userName like '$_POST[userName]';";
$resultID=mysql_query($query);
if (!$resultID) {
  echo "Error selecting ID from Account: " . mysql_error();
  die("");
}
$userID=mysql_result($resultID,0, "ID");

/*
$query="
SELECT ID FROM Trail where headID=$headID;
";
$resultTrails=mysql_query($query);
if (!$resultTrails) {
  echo "Error selecting ID from Trail: " . mysql_error();
}
$numTrails=mysql_numrows($resultTrails);

// deletes all reviews associated w/ all trails being removed
for ($i=0; $i<$numTrails; $i++) {
$trailID=mysql_result($resultTrails,$i,"ID");
$query="DELETE FROM Review where trailID=$trailID;";
  if (!$mysql_query($query)) {
    echo "Error deleting reviews: " . mysql_error();
  }
}
*/

// deletes all visited trails associated w/ the user
$query=" DELETE FROM Saved where userID=$userID; ";
if (!$mysql_query($query)) {
  echo "Error deleting from Saved: " . mysql_error();
}

// deletes the reviews associated w/ the user
$query=" DELETE FROM Review where userID=$userID; ";
if (!$mysql_query($query)) {
  echo "Error deleting Review: " . mysql_error();
}

// deletes the filters associated w/ the user
$query=" DELETE FROM Filter where userID=$userID; ";
if (!$mysql_query($query)) {
  echo "Error deleting Filter: " . mysql_error();
}

// deletes the user from Account
$query=" DELETE FROM Account where ID=$userID; ";
if (!$mysql_query($query)) {
  echo "Error deleting from Account: " . mysql_error();
}

mysql_close();
header("Location: index.php");
ob_flush();
?> 
